<?php
include "include/config.inc.php";
$select = "SELECT * from installment
                ORDER BY loanId,installmentDate";
$selectRes=mysql_query($select);
$currentLoanId = 0;
while($row=mysql_fetch_array($selectRes))
{
  if($currentLoanId != $row['loanId'])
  {
    $installmentNo = 0;
    $currentLoanId = $row['loanId'];
  }
  $installmentNo++;
  
  echo "<br>".$update = "UPDATE installment 
                set installmentNo = ".$installmentNo."
              WHERE installmentId = ".$row['installmentId'];
  $updateRes=mysql_query($update);              
}
?>